//
//  MainManager.swift
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/7/21.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit
class MainManager: BaseManager {
    private static let instance = MainManager()
    static func sharedManager() -> MainManager{
        return instance
    }
    func login(userName:String,pwd:String,callback:@escaping(_ result:Result)->()) {
        let loginUrl = "http://zxlapp3.zxlshop.com/zxlapp/member/login"
        let dic = ["username":userName,"password":pwd.toBase64()!]
        NetworkHelper.request(type:.post,url: loginUrl, parameters: dic, responseOKCallback: { (response) in
            print(response)
            let data = response["returnContent"]
            let money = data["mobile"].string
            let companyNameList = data["companyNameList"][0].string
            let token = data["token"].string
            UserDefaultsManager.saveUserToken(token: token!)
            print(money!+";;;;;;;"+companyNameList!)
            callback(.Result_OK)
        }, codeErrorCallback: { (response, codeStr) in
            callback(.Result_CodeError)
        }) { (error) in
            callback(.Result_Failure)
        }
        
    }
    func showPage() {
        let url = "http://zxlapp3.zxlshop.com/zxlapp/index/showPage"
        let dic: Dictionary = ["areaid":"1"]
        NetworkHelper.request(type:.get,url: url, parameters: dic, responseOKCallback: { (response) in
            print("/////////\(response)")
        }, codeErrorCallback: { (response, codeStr) in
            
        }) { (error) in
            
        }
    }
    func getAnnouncelist() {
        let url = "http://zxlapp3.zxlshop.com/zxlapp/index/announceList"
        let dic: Dictionary = ["pageNo":"1"]
        NetworkHelper.request(type: .post, url: url, parameters: dic, responseOKCallback: { (response) in
            
        }, codeErrorCallback: { (response, codeStr) in
            
        }) { (error) in
            
        }
    }
    func download() {
        let loginUrl = "https://ceshi.zxlshop.com/file/upload/usercontractscan/20200727104855-892-buy-200020.pdf"
//        NetworkHelper.download(url: loginUrl)
    }
    func upload(image:UIImage) {
        let url = "http://zxlapp3.zxlshop.com/zxlapp/index/announceList"
        NetworkHelper.upload(url: url, params: ["":""], image: image, successCallback: { (response) in
            
        }) { (error) in
            
        }
    }
}
